﻿using LPLS.WPFBaseLibrary;
using System.Collections;
using System.Windows;
using static LPLS.WPFBaseLibrary.BaseChartControl;

namespace ChartDemo;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new MainWindowViewModel();
    }

    private void PieChart_DataClicked(object sender, ChartDataClickedEventArgs e)
    {
        ShowDetailWindow(e.Data);
    }

    private void BarChart_DataClicked(object sender, ChartDataClickedEventArgs e)
    {
        ShowDetailWindow(e.Data);
    }

    private void LineChart_DataClicked(object sender, ChartDataClickedEventArgs e)
    {
        ShowDetailWindow(e.Data);
    }

    private void ShowDetailWindow(object? data)
    {
        if (data is IEnumerable detailList)
        {
            var win = new DetailDataWindow(detailList);
            win.Owner = this;
            win.ShowDialog();
        }
        else if (data != null)
        {
            var win = new DetailDataWindow(new[] { data });
            win.Owner = this;
            win.ShowDialog();
        }
    }
}